
//////////

// 注册验证
var is_mine, company_name, user_name, position, mobileCom, codeCom;
var source = window.location.search.split("?dealer=")[1];
var arr = [];
//手机的值,并进行编码
window.onload = function(){
	if(source == 142){
		$('.yx-con').css('display','block');
	}
}
$('.person').click(function () {
    is_mine = 1;
    $('.person').addClass('person-active-img')
    $('.next-btn-a').addClass('active-btn')
    $('.person-radio').addClass('p-active-radio')
    $('.company').removeClass('company-active-img')
    $('.company-radio').removeClass('active-radio')
})
$('.person-radio').click(function () {
    is_mine = 1;
    $('.person').addClass('person-active-img')
    $('.next-btn-a').addClass('active-btn')
    $('.person-radio').addClass('p-active-radio')
    $('.company').removeClass('company-active-img')
    $('.company-radio').removeClass('active-radio')
})
$('.company').click(function () {
    is_mine = 2;
    $('.company').addClass('company-active-img')
    $('.next-btn-a').addClass('active-btn')
    $('.company-radio').addClass('active-radio')
    $('.person').removeClass('person-active-img')
    $('.person-radio').removeClass('p-active-radio')
})
$('.company-radio').click(function () {
    is_mine = 2;
    $('.company').addClass('company-active-img')
    $('.next-btn-a').addClass('active-btn')
    $('.company-radio').addClass('active-radio')
    $('.person').removeClass('person-active-img')
    $('.person-radio').removeClass('p-active-radio')
})
$('#zc_btn').click(function () {
    document.getElementById('light').style.display = 'block';
    document.getElementById('fade').style.display = 'block';
})
$('.select-action').click(function () {
    if ($('.select-con').height() == 0) {
        $('.select-con').animate({ 'height': '224px', 'padding-top': '10px' })
        $('.select-con2').animate({ 'height': '0px', 'padding-top': '0' })
        $('.select-con3').animate({ 'height': '0px', 'padding-top': '0' })
    } else {
        $('.select-con').animate({ 'height': '0px', 'padding-top': '0' })
    }
})
$('.select-con').on('click', 'li', function (e) {
    $('.select-font').text($(this).text());
    $('.select-font').addClass('active-select');
    $('.select-con').animate({ 'height': '0px', 'padding-top': '0' })
})
$('.select-action2').click(function () {
    if ($('.select-con2').height() == 0) {
        $('.select-con2').animate({ 'height': '124px', 'padding-top': '10px' })
        $('.select-con').animate({ 'height': '0px', 'padding-top': '0' })
        $('.select-con3').animate({ 'height': '0px', 'padding-top': '0' })
    } else {
        $('.select-con2').animate({ 'height': '0px', 'padding-top': '0' })
    }
})
$('.clear_icon').on('click', function (e) {
	if($('.select-font2').text() !== '请选择您的需求'){
		$('.select-font2').text('请选择您的需求')
    $('.select-font2').removeClass('active-select');
		arr= []
		$('.clear_icon').css('display','none')
	}
})
$('.select-con2').on('click', 'li', function (e) {
		if($('.select-font2').text() == '请选择您的需求'){
			$('.select-font2').text('')
		}
		if(arr.length){
			if(!arr.find((el)=>el==$(this).text())){
				arr.push($(this).text())
				$('.select-font2').text($('.select-font2').text()+' '+$(this).text());
			}
		}else{
			arr.push($(this).text())
			$('.select-font2').text($('.select-font2').text()+' '+$(this).text());
			$('.clear_icon').css('display','inline-block')
		}
		console.log(arr,$(this).text())
    $('.select-font2').addClass('active-select');
    $('.select-con2').animate({ 'height': '0px', 'padding-top': '0' })
})
$('.select-action3').click(function () {
    if ($('.select-con3').height() == 0) {
        $('.select-con3').animate({ 'height': '150px', 'padding-top': '10px' })
        $('.select-con').animate({ 'height': '0px', 'padding-top': '0' })
        $('.select-con2').animate({ 'height': '0px', 'padding-top': '0' })
    } else {
        $('.select-con3').animate({ 'height': '0px', 'padding-top': '0' })
    }
})
$('.select-con3').on('click', 'li', function (e) {
    $('.select-font3').text($(this).text());
    $('.select-font3').addClass('active-select');
    $('.select-con3').animate({ 'height': '0px', 'padding-top': '0' })
})
var inEle = document.getElementById("online-consults");
var num = 90;
var apiUrl = 'https://www.feeclouds.com';
//var apiUrl = 'http://182.92.1.42:8084';
let luotest_response=""
function callback(msg){
    luotest_response=msg
    $(".send_yzm").css({
        zIndex:100
    })
    sendcode()
}
$(".send_yzm").click(function () {
    if(Object.getOwnPropertyNames(LUOCAPTCHA.data).length==0){
        LUOCAPTCHA.render()
        $(".error_t_t")[0].innerText = "人机验证失败,请重试";
    }
})
function onReset(){
    luotest_response="";
    LUOCAPTCHA.reset()
    $(".send_yzm").css({
        zIndex:0
    })
}
function sendcode() {
    var mobile = encodeURIComponent($("#inp_iphone").val());
    if (!mobile) {
        $(".error_t_t")[0].innerText = "请输入手机号";
        onReset()
    } else if (!(/^1[3456789]\d{9}$/.test(mobile))) {
        $(".error_t_t")[0].innerText = "请输入正确的手机号";
        onReset();
    }else {
        $(".error_t_t")[0].innerText = "";
        $.ajax({
            url: apiUrl + '/homepage/register/send',
            type: "POST",
            data: {
                mobile: mobile,
                luotest_response
            },
            success: function (data) {
                if (data.code == 0) {
                    $('.send_yzm').text(num + "秒后重新发送");
                    var fate = setInterval(function () {
                        num--;
                        $('.send_yzm').text(num + "秒后重新发送");
                        if (num === 0) {
                            $('.send_yzm').text('发送验证码');
                            clearInterval(fate)
                            num = 90
                            onReset()
                        }
                    }, 1000)
                } else {
                    alert(data.msg)
                    onReset()
                }
            }
        });
    }
};
$('.input').blur(function () {

})
var _taq = [],a=1;
$(".next-btn").click(function () {
    company_name = $("#inp_company").val();
    user_name = $("#inp_name").val();
    position = $(".select-font").text();
    demand = arr.join(',');
		invoice_count = $(".select-font3").text();
    mobileCom = encodeURIComponent($("#inp_iphone").val());
    codeCom = $("#inp_code").val();
    if (!company_name) {
        $(".error_c_t")[0].innerText = "请输入公司名称";
    } else if (!/^([\u4e00-\u9fa5A-Za-z0-9,.?!;，。？！、；])*$/.test(company_name)) {
        $(".error_c_t")[0].innerText = "存在特殊字符";
    } else if (!user_name) {
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "请输入姓名";
    } else if (!/^([\u4e00-\u9fa5A-Za-z0-9,.?!;，。？！、；])*$/.test(user_name)) {
        $(".error_n_t")[0].innerText = "存在特殊字符";
    } else if (!position || position == '请选择所属部门') {
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "";
        $(".error_d_t")[0].innerText = "请选择所属部门";
    }else if ((!demand || demand == '请选择您的需求') && source == 142) {
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "";
        $(".error_d_t")[0].innerText = "";
        $(".error_x_t")[0].innerText = "请选择您的需求";
    }else if((!invoice_count || invoice_count == '请选择月进项票') && source == 142){
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "";
        $(".error_d_t")[0].innerText = "";
        $(".error_x_t")[0].innerText = "";
        $(".error_i_t")[0].innerText = "请选择月进项票";
    }else if (!mobileCom) {
    $(".error_c_t")[0].innerText = "";
    $(".error_n_t")[0].innerText = "";
    $(".error_d_t")[0].innerText = '';
    if(source == 142){
        $(".error_x_t")[0].innerText = "";
        $(".error_i_t")[0].innerText = "";
    }
    $(".error_t_t")[0].innerText = "请输入手机号";
    } else if (!(/^1[3456789]\d{9}$/.test(mobileCom))) {
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "";
        $(".error_d_t")[0].innerText = '';
        if(source == 142){
            $(".error_x_t")[0].innerText = "";
            $(".error_i_t")[0].innerText = "";
        }
        $(".error_t_t")[0].innerText = "请输入正确的手机号";
    } else if ($('.code_t').val() == "") {
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "";
        $(".error_d_t")[0].innerText = '';
        $(".error_t_t")[0].innerText = '';
        if(source == 142){
            $(".error_x_t")[0].innerText = "";
            $(".error_i_t")[0].innerText = "";
        }
        $(".error_y_t")[0].innerText = "验证码不能为空";
    } else {
        $(".error_c_t")[0].innerText = "";
        $(".error_n_t")[0].innerText = "";
        $(".error_d_t")[0].innerText = '';
        $(".error_t_t")[0].innerText = '';
        $(".error_y_t")[0].innerText = '';
        if(source == 142){
            $(".error_x_t")[0].innerText = "";
            $(".error_i_t")[0].innerText = "";
        }
        if(a == 1){
            a = 2;
            // $.ajax({
            //     url: apiUrl + '/homepage/register/company',
            //     type: "POST",
            //     data: {
            //         mobile: mobileCom,
            //         code: codeCom,
            //         company_name: company_name,
            //         user_name: user_name,
            //         position: position,
            //                         source: source ? source : "100",
            //                         demand: demand ,
            //                         invoice_count: invoice_count =='请选择月进项票'?'':invoice_count,
            //     },
            //     success: function (data) {
            //         a = 1;
            //         if (data.code !== 0) {
            //             alert(data.msg); return;
            //         }
            //         if (source === '101') {
            //             _taq.push({ convert_id: "92045420305", event_type: "form" })
            //         }
            //         $('.form-con').hide()
            //         $('.person-con').show()
            //     },
            //     error: function (data) {
            //         a = 1;
            //         alert(data.msg)
            //     },
            // });

        }
    }
});
